﻿Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Net
Imports System.Xml
Imports System.Web.Services.Protocols
Imports DevExpress.XtraGrid.Views.Grid
Public Class frmOPService
    Dim DA As New MySqlDataAdapter
    Dim MyConn As New MySqlConnection
    Dim mysql As New ClsSQLhelper
    Dim DSOPPP As New OPPP
    Dim Strsql As String
    Dim Curr_View As String = "OP9200"
    Dim On_load As Boolean = True
    Dim ClsService As New ClsServices
    Dim MainStrsql As String = "select m_service.PCUCODE,m_service.PID,m_person.CID,m_person.HN,Concat(m_person.NAME,'  ',m_person.LNAME)" & _
    " as NAME,m_person.SEX,m_person.BIRTH,m_person.MSTATUS as MSTATUS,m_person.OCCUPA,m_person.NATION,m_person.TYPEAREA," & _
    " m_service.SEQ, m_service.DATE_SERV, m_service.CLINIC,m_service.SUBCLINIC,m_service.LOCATE, m_service.PRICE, m_service.PAY,m_service.COST,m_service.PTTYPE,m_service.INTIME,m_service.INSTYPE,m_service.INSID, m_service.SERVICE_TYPE, " & _
    " m_service.REFERIN,m_service.REFINHOS,m_service.REFEROUT,m_service.REFOUHOS,m_service.CODE_ID  from m_service left join m_person on  m_service.PID = m_person.PID  "



#Region "Function"
    Sub Search_Information()
        Try
            If Me.VGR_PID.Properties.Value = "000000" Then
                MsgBox("ไม่สามารถหาความเชื่อมโยงได้เนื่องจาก PID = 000000")
                Exit Sub
            End If
            Select Case Me.VGR_CID.Properties.Value
                Case "0000000000000"
                    If MsgBox("รหัสบัตรไม่ถูกกต้อง คุณยืนยันที่จะค้นหาต่อหรือไม่", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "คำเตือน") = MsgBoxResult.No Then Exit Sub
                    frmSearchInfo.TxtCriteria.Text = Me.VGR_PID.Properties.Value
                Case ""
                    If Me.VGR_HN.Properties.Value <> "ไม่ระบุ" Then

                        frmSearchInfo.TxtCriteria.Text = Me.VGR_HN.Properties.Value
                    Else
                        If Me.VGR_PID.Properties.Value <> "" Then
                            frmSearchInfo.TxtCriteria.Text = Me.VGR_PID.Properties.Value
                        ElseIf Me.VGR_Fullname.Properties.Value <> "" Then
                            frmSearchInfo.TxtCriteria.Text = Me.VGR_Fullname.Properties.Value
                        Else

                            MsgBox("ไม่สามารถ หาความเชื่อมโยงได้", MsgBoxStyle.Critical)
                        End If

                    End If
                Case Else
                    frmSearchInfo.TxtCriteria.Text = Me.VGR_CID.Properties.Value
            End Select
            With frmSearchInfo
                .TxtYear.Text = Me.TxtYear.Text
                .TxtMonth.Text = Me.TxtMonth.Text
                '.TxtDateServ.Text = Me.TxtDateServ.Text
                .Submit_Search()
                .ShowDialog()
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub GenScript()
        Try
            Dim Strsql As String = " CID in ("
            Dim HNSql As String = " HN in ("
            Dim PIDsql As String = " person_id in ("
            Select Case Me.Curr_View

                Case "OP9200"

                    For i As Integer = 0 To DataGridView1.RowCount - 1

                        Strsql = Strsql & "'" & DataGridView1.Rows(i).Cells("CID").Value.ToString.Trim() & "',"
                        HNSql = HNSql & "'" & DataGridView1.Rows(i).Cells("HN").Value.ToString.Trim() & "',"
                        PIDsql = PIDsql & "'" & DataGridView1.Rows(i).Cells("PID").Value.ToString.Trim() & "',"
                    Next
                    Strsql = Mid(Strsql, 1, Len(Strsql) - 1) & ")"
                    HNSql = Mid(HNSql, 1, Len(HNSql) - 1) & ")"
                    PIDsql = Mid(PIDsql, 1, Len(PIDsql) - 1) & ")"
                    SQLDialog.Sqltext.Text = Strsql
                    SQLDialog.Sqltext2.Text = HNSql
                    SQLDialog.Sqltext3.Text = PIDsql

                    SQLDialog.ShowDialog()

                Case Else
                    Strsql = " CID in ("
                    For i As Integer = 0 To DataGridView1.RowCount - 1

                        Strsql = Strsql & "'" & DataGridView1.Rows(i).Cells("CID").Value.ToString.Trim() & "',"
                        HNSql = HNSql & "'" & DataGridView1.Rows(i).Cells("HN").Value.ToString.Trim() & "',"
                        PIDsql = PIDsql & "'" & DataGridView1.Rows(i).Cells("PID").Value.ToString.Trim() & "',"
                    Next
                    Strsql = Mid(Strsql, 1, Len(Strsql) - 1) & ")"
                    HNSql = Mid(HNSql, 1, Len(HNSql) - 1) & ")"
                    PIDsql = Mid(PIDsql, 1, Len(PIDsql) - 1) & ")"
                    SQLDialog.Sqltext.Text = Strsql
                    SQLDialog.Sqltext2.Text = HNSql
                    SQLDialog.Sqltext3.Text = PIDsql

                    SQLDialog.ShowDialog()

            End Select

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub Load_Summary()
        Try
            Strsql = "select CODE_ID,Count(CODE_ID) as Totalrows from m_service where filename = " & CboImportOPFile.SelectedValue & " and CODE_ID is not null  group by CODE_ID "
            Dim DT_Service As New DataTable
            DT_Service = mysql.GetMYSQLDataTable(Strsql, "ERROR_Summary")

            With Grid_ErrorCode
                .DataSource = DT_Service

            End With

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub Load_Data(ByVal Code_ID As String, Optional ByVal StrAddonSql As String = "")
        Try

            Me.Cursor = Cursors.WaitCursor
            Me.Curr_View = Code_ID
            Strsql = MainStrsql & " where m_service.CODE_ID  like  '%" & Code_ID & "%'  " & " " & StrAddonSql & "  and m_service.FILENAME = " & Me.CboImportOPFile.SelectedValue
            'If Me.ChkShowPIDError.Checked = False Then
            '    Strsql = Strsql & " and  m_mch.pid <> 000000 "
            'End If
            'If Me.ChkShowNewBorn.Checked = False Then
            '    Strsql = Strsql & " and  m_person.NAME not like '(%' "
            'End If
            Strsql = Strsql & " order by  m_service.PID desc"


            '  DA = New MySqlDataAdapter(Strsql, MyConn)
            ' DA.Fill(DSOPPP, "m_person")
            Dim DT_Service As New DataTable
            DT_Service = mysql.GetMYSQLDataTable(Strsql, "m_service")
          
            With DataGridView1

                .RowHeadersVisible = False
                .AllowDrop = False
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToOrderColumns = True
                .AllowUserToResizeColumns = True
                .AllowUserToResizeRows = False
                .MultiSelect = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
                .DataSource = DT_Service

                If .RowCount < 1 Then
                    MsgBox("ไม่พบข้อมูล", MsgBoxStyle.Exclamation)
                Else
                    MsgBox("ดึงข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                End If
            End With
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            MsgBox(ex.Message)
        End Try

    End Sub
#End Region


    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Try
            Dim Error_Code As String

            With Me.DataGridView1
                Dim MyPerson As New ClsPerson
                MyPerson.Get_NHSO_Profile(.Rows(e.RowIndex).Cells("PID").Value.ToString.Trim)

                Me.VGR_CID.Properties.Value = MyPerson.CID
                Me.VGR_PID.Properties.Value = .Rows(e.RowIndex).Cells("PID").Value.ToString.Trim
                Me.VGR_Fullname.Properties.Value = MyPerson.Get_Person_FullName
                Me.VGR_HN.Properties.Value = MyPerson.HN
                Me.VGR_MStatus.Properties.Value = MyPerson.MStatus
                Me.VGR_FormatCID.Properties.Value = MyPerson.Get_Person_FormatCID
                Me.VGR_Nationality.Properties.Value = MyPerson.Nation
                Me.VGR_Occupation.Properties.Value = MyPerson.Ocupaton
                Me.VGR_Race.Properties.Value = MyPerson.Race
                Me.VGR_Sex.Properties.Value = MyPerson.Sex
                Me.VGR_TypeArea.Properties.Value = MyPerson.TypeArea
                Me.VGA_BirthDay.Properties.Value = MyPerson.BirthDay
                Me.VGA_AGE.Properties.Value = MyPerson.Age



                ' Me.VGR_Fullname.Properties.Value = .Rows(e.RowIndex).Cells("CID").Value.ToString.Trim
                ' Me.VGR_CID.Properties.Value = .Rows(e.RowIndex).Cells("CID").Value.ToString.Trim
                'Me.VGR_FormatCID.Properties.Value = .Rows(e.RowIndex).Cells("HN").Value.ToString.Trim
                ' Me.VGR_PID.Properties.Value = .Rows(e.RowIndex).Cells("PID").Value.ToString.Trim
                'Me. .Properties.Value = DataGridView1.Rows(e.RowIndex).Cells("CODE_ID").Value.ToString.Trim
                'Me.Properties.Value = DataGridView1.Rows(e.RowIndex).Cells("DATE_SERV").Value.ToString.Trim
                'Me.TXTGA.Properties.Value = DataGridView1.Rows(e.RowIndex).Cells("GA").Value.ToString.Trim
                'Me.TxtANCRES.Properties.Value = DataGridView1.Rows(e.RowIndex).Cells("ANCRES").Value
                Error_Code = DataGridView1.Rows(e.RowIndex).Cells("CODE_ID").Value

                If Mid(Error_Code, 1, 1) = "," Then
                    Error_Code = Mid(Error_Code, 2, Error_Code.Length)
                End If
                If InStr(Error_Code, ",", CompareMethod.Text) > 0 Then
                    Error_Code = Replace(Error_Code, ",", "','")
                End If
                Strsql = "select code_id,remark from l_error_code where code_id in ('" & Error_Code & "')"
                Dim DT_ERROR As New DataTable
                DT_ERROR = mysql.GetMYSQLDataTable(Strsql, "l_error_code")
                With ErrorDesc_Grid
                    .DataSource = DT_ERROR
                End With
            End With



            Dim DTDiag As New DataTable
            Dim StrDiagSql As String = "select DIAGCODE,DIAGTYPE,CODE_ID,DESC_R from m_diag  left join l_icd10 on m_diag.DIAGCODE=l_icd10.CODE where m_diag.pid = " & Me.VGR_PID.Properties.Value & " and m_diag.FILENAME = " & Me.CboImportOPFile.SelectedValue
            DTDiag = mysql.GetMYSQLDataTable(StrDiagSql, "m_diag")
            Dim DTProcess As New DataTable
            Dim StrProcessSql As String = "select PROCED,CODE_ID,DESC_R from m_proced  left join l_icd9 on m_proced.PROCED=l_icd9.CODE where pid = " & Me.VGR_PID.Properties.Value & " and FILENAME = " & Me.CboImportOPFile.SelectedValue
            DTProcess = mysql.GetMYSQLDataTable(StrProcessSql, "m_proced")
            Dim DTDrug As New DataTable
            Dim StrDrugSql As String = "select DIDSTD,CODE_ID,drugname from m_drug left join l_drugs on m_drug.DIDSTD =l_drugs.STD_CODE  where pid = " & Me.VGR_PID.Properties.Value & " and FILENAME = " & Me.CboImportOPFile.SelectedValue
            DTDrug = mysql.GetMYSQLDataTable(StrDrugSql, "m_drug")
            With DiagGrid
                .RowHeadersVisible = False
                .AllowDrop = False
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToOrderColumns = True
                .AllowUserToResizeColumns = True
                .AllowUserToResizeRows = False
                .MultiSelect = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
                .DataSource = DTDiag
            End With
            With ProcessGrid
                .RowHeadersVisible = False
                .AllowDrop = False
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToOrderColumns = True
                .AllowUserToResizeColumns = True
                .AllowUserToResizeRows = False
                .MultiSelect = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
                .DataSource = DTProcess
            End With
            With DrugGrid
                .RowHeadersVisible = False
                .AllowDrop = False
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToOrderColumns = True
                .AllowUserToResizeColumns = True
                .AllowUserToResizeRows = False
                .MultiSelect = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
                .DataSource = DTDrug

            End With
            If DataGridView1.Rows(e.RowIndex).Cells("REFOUHOS").Value.ToString <> "" Then
                Strsql = "select concat(hosptype,name) from hospcode where hospcode = '" & DataGridView1.Rows(e.RowIndex).Cells("REFOUHOS").Value.ToString & "'"
                VGR_HOSxP_HOSP.Properties.Value = mysql.MySQLExecuteScalar(Strsql, "hos")
                Strsql = "select name from l_hospitals where pcucode = '" & DataGridView1.Rows(e.RowIndex).Cells("REFOUHOS").Value.ToString & "'"
                VGR_NHSO_HOSP.Properties.Value = mysql.MySQLExecuteScalar(Strsql)

            ElseIf DataGridView1.Rows(e.RowIndex).Cells("REFINHOS").Value.ToString <> "" Then
                Strsql = "select concat(hosptype,name) from hospcode where hospcode = '" & DataGridView1.Rows(e.RowIndex).Cells("REFINHOS").Value.ToString & "'"
                VGR_HOSxP_HOSP.Properties.Value = mysql.MySQLExecuteScalar(Strsql, "hos")
                Strsql = "select name from l_hospitals where pcucode = '" & DataGridView1.Rows(e.RowIndex).Cells("REFINHOS").Value.ToString & "'"
                VGR_NHSO_HOSP.Properties.Value = mysql.MySQLExecuteScalar(Strsql)

            Else
                VGR_NHSO_HOSP.Properties.Value = ""
                VGR_NHSO_HOSP.Properties.Value = ""
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub frmOPService_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Me.VGR_CID.Properties.Value = "0000000000000"
            Dim DT_m_files_upload As DataTable
            Strsql = "select ROWID,FILENAME from m_files_upload "
            Strsql = Strsql & " where TYPE_DESC = 'OP Package' or  TYPE_DESC = '18 แฟ้ม' "
            Strsql = Strsql & " order by Date_SEND DESC"


            With Me.CboImportOPFile

                DT_m_files_upload = mysql.GetMYSQLDataTable(Strsql, "m_files_upload")
                If DT_m_files_upload.Rows.Count = 0 Then
                    MsgBox("คุณต้องนำข้อมูลเข้าโปรแกรมตรวจสอบ NHSO OPPP 2554 ก่อน", MsgBoxStyle.Exclamation)
                    Exit Sub
                End If
                .DataSource = DT_m_files_upload
                .DisplayMember = "FILENAME"
                .ValueMember = "ROWID"
                Me.CboImportOPFile.SelectionStart = DT_m_files_upload.Rows(0).Item("ROWID").ToString

            End With
            If InStr(Me.CboImportOPFile.Text, "FOP", CompareMethod.Text) > 0 Then
                Me.TxtYear.Text = Mid(Me.CboImportOPFile.Text, 11, 4)
                Me.TxtMonth.Text = Mid(Me.CboImportOPFile.Text, 15, 2)
            End If
            If InStr(Me.CboImportOPFile.Text, "E_PCU", CompareMethod.Text) > 0 Then
                'E_PCU_11266_201010_20101202.zip
                Me.TxtYear.Text = Val(Mid(Me.CboImportOPFile.Text, 13, 4)) + 543
                Me.TxtMonth.Text = Mid(Me.CboImportOPFile.Text, 17, 2)
            End If
            Load_Summary()

            Strsql = "Select (((AMOUNT-ERROR)/amount))*100 as point from m_upload where filename = 'SERVICE'"
            Dim MyPoint As String
            MyPoint = mysql.MySQLExecuteScalar(Strsql)
            Me.CircularGauge1.Scales(0).Value = Val(MyPoint)
            Me.CircularGauge1.Labels(0).Text = FormatNumber(MyPoint, 2) & " %"


            On_load = False
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        '(MyConn.ConnectionString = ClsSQLhelper.MySQLConnectionStr)
        ' Read_DataQuality()
    End Sub




    Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
        Search_Information()
    End Sub

    Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
        If e.KeyCode = Keys.F5 Then
            Search_Information()
        End If
    End Sub

    Private Sub CboImportOPFile_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboImportOPFile.SelectedIndexChanged
        Try
            If On_load = True Then Exit Sub
            If InStr(Me.CboImportOPFile.Text, "FOP", CompareMethod.Text) > 0 Then
                Me.TxtYear.Text = Mid(Me.CboImportOPFile.Text, 11, 4)
                Me.TxtMonth.Text = Mid(Me.CboImportOPFile.Text, 15, 2)
            End If
            If InStr(Me.CboImportOPFile.Text, "E_PCU", CompareMethod.Text) > 0 Then
                'E_PCU_11266_201010_20101202.zip
                Me.TxtYear.Text = Val(Mid(Me.CboImportOPFile.Text, 13, 4)) + 543
                Me.TxtMonth.Text = Mid(Me.CboImportOPFile.Text, 17, 2)
            End If

            '  Read_DataQuality()
            Load_Summary()
            'Select Case Me.Curr_View
            '    Case "OP9200"
            '        BtnOP9200_Click(sender, e)
            '    Case "OP9299"
            '        BtnOP9299_Click(sender, e)
            'End Select
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub









    Private Sub ProcessGrid_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ProcessGrid.CellClick
        'Try
        '    Me.lblDescription.Text = "รหัส PROCED ไม่ถูกต้อง"
        '    With DiagGrid
        '        Strsql = "select DESC_R from l_icd9 where CODE = '" & .Rows(0).Cells(0).Value.ToString & "'"
        '        Me.lblDescription.Text = mysql.MySQLExecuteScalar(Strsql)
        '    End With


        'Catch ex As Exception
        '    MsgBox(ex.Message)
        'End Try
    End Sub

    Private Sub ProcessGrid_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ProcessGrid.CellContentClick

    End Sub

    Private Sub DiagGrid_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DiagGrid.CellClick
        'Try
        '    Me.lblDescription.Text = "รหัส Diag ไม่ถูกต้อง"
        '    With DiagGrid
        '        Strsql = "select DESC_R from l_icd10 where CODE = '" & .Rows(0).Cells(0).Value.ToString & "'"
        '        Me.lblDescription.Text = mysql.MySQLExecuteScalar(Strsql)
        '    End With
        'Catch ex As Exception
        '    MsgBox(ex.Message)
        'End Try
    End Sub

    Private Sub DiagGrid_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DiagGrid.CellContentClick

    End Sub

    Private Sub Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub AnalysisToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnalysisToolStripMenuItem.Click
        With frmAnalysisNoRelation
            .DateServ = ClsService.DateService
            .PTTYPE = ClsService.Patient_PTTYPE
            .income = ClsService.Income_Money
            .Rcpt_Money = ClsService.Receive_Money
            .ShowDialog()

        End With
    End Sub

    Private Sub RBM_OP9200_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_OP9200.ItemClick
        Load_Data("OP9200")
    End Sub

    Private Sub RBM_GenScript_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_GenScript.ItemClick
        If Me.DataGridView1.RowCount = 0 Then Exit Sub
        GenScript()
    End Sub

    Private Sub RBM_Excel_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_Excel.ItemClick
        If Me.DataGridView1.RowCount = 0 Then Exit Sub


        If Me.DataGridView1.RowCount = 0 Then Exit Sub
        If MsgBox("คุณต้องการส่งออกข้อมูลในตาราง ออกเป็นรูปแบบ Excel หรือไม่", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Export to Excel") = MsgBoxResult.No Then Exit Sub


        With SaveFileDialog1
            .FileName = Me.Text
            .Filter = "Excel 2003 | *.xls"
            If .ShowDialog() <> DialogResult.OK Then Exit Sub

            Dim Str As String = "" ' = "PCUCODE,PID,HN,CID,NAME,SEX,BIRTH,MSTATUS,OCCUPA,NATION,TYPEAREA,CODE_ID"
            For i = 0 To DataGridView1.ColumnCount - 1
                Str = Str & DataGridView1.Columns(i).HeaderText
                If i <> DataGridView1.ColumnCount - 1 Then
                    Str = Str & ","
                End If

            Next
            Using sw As StreamWriter = New StreamWriter(.FileName, False, System.Text.Encoding.UTF8)
                sw.WriteLine(Str)

                '  
                For i As Integer = 0 To DataGridView1.RowCount - 1
                    Str = ""
                    For j As Integer = 0 To DataGridView1.ColumnCount - 1
                        Str = Str & DataGridView1.Rows(i).Cells(j).Value.ToString
                        If j <> DataGridView1.ColumnCount - 1 Then
                            Str = Str & ","
                        End If

                    Next
                    sw.WriteLine(Str)
                Next
                sw.Close()

            End Using


            MsgBox("ส่งออกข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)

        End With
    End Sub

    Private Sub RBM_Find_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_Find.ItemClick
        Search_Information()

    End Sub

    Private Sub RBM_OP9299_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_OP9299.ItemClick
        Load_Data("OP9299")
    End Sub

    Private Sub RBM_9205_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_9205.ItemClick
        Load_Data("OP9205")
    End Sub

    Private Sub BarButtonItem4_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_OP2103.ItemClick
        Load_Data("OP2103")
    End Sub

    Private Sub RBM_OP9225_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_RF9225.ItemClick
        Load_Data("RF9225")
    End Sub

    Private Sub RBM_RF9226_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_RF9226.ItemClick
        Load_Data("RF9226")
    End Sub

    Private Sub RBM_SE1104_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1104.ItemClick
        Load_Data("SE1104")
    End Sub

    Private Sub RBM_SE1105_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1105.ItemClick
        Load_Data("SE1105")
    End Sub

    Private Sub RBM_SE1106_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1106.ItemClick
        Load_Data("SE1106")
    End Sub

    Private Sub RBM_SE1120_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1120.ItemClick
        Load_Data("SE1120")
    End Sub

    Private Sub RBM_SE1121_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1121.ItemClick
        Load_Data("SE1121")
    End Sub


    Private Sub RBM_SE1125_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1125.ItemClick
        Load_Data("SE1125")
    End Sub

    Private Sub RBM_SE1126_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1126.ItemClick
        Load_Data("SE1126")
    End Sub

    Private Sub RBM_SE1127_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1127.ItemClick
        Load_Data("SE1127")
    End Sub

    Private Sub RBM_SE1128_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1128.ItemClick
        Load_Data("SE1128")
    End Sub

    Private Sub RBM_SE1140_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_SE1140.ItemClick
        Load_Data("SE1140")
    End Sub

    Private Sub RBM_OP9206_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_OP9206.ItemClick
        Load_Data("OP9206")
    End Sub

    Private Sub RBM_OP9230_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles RBM_OP9230.ItemClick
        Load_Data("OP9230")
    End Sub


    Private Sub GridView2_CustomRowCellEditForEditing(ByVal sender As System.Object, ByVal e As DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs) Handles GridView2.CustomRowCellEditForEditing
        Try
            'If e.Column.FieldName = "Totalrows" Then Return
            Dim Gv As GridView = sender
            Dim CodeName As String = Gv.GetRowCellValue(e.RowHandle, _
              Gv.Columns("CODE_ID")).ToString()
            Load_Data(CodeName)
        Catch ex As Exception

        End Try
    End Sub
End Class